/**
 * @param {string} first
 * @param {string} second
 * @return {boolean}
 */
export var oneEditAway = function (first, second) {
  const [m, n] = [first.length, second.length]
  if (m < n) return oneEditAway(second, first)
  if (m - n > 1) return false
  let countDiff = 0
  let i = 0
  while (i < m) {
    const charA = first[i]
    const charB = second[i] || null
    if (charA !== charB) {
      if (m === n) {
        countDiff++
        if (countDiff > 1) return false
      } else {
        const strA = first.slice(i + 1)
        const strB = second.slice(i)
        if (strA !== strB) return false
      }
    }
    i++
  }
  return true
}
